package com.cwhuang.g7_tool_myhymns;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.app.Application;
import android.util.Log;

/**
 * @author G7
 *	這是要用來存放整個app都能共用的hymns資料庫
 */
public class AppHymns extends Application {
	public final static String COL_SERIAL = "col_serial";
	public final static String COL_INDEX = "col_index";
	public final static String COL_TITLE = "col_title";
	public final static String COL_RATING = "col_rating";
	public final static String COL_TIMES = "col_times";
	public final static String COL_FAMILIARITY = "col_familiarity";
	public final static String COL_STYLES = "col_style";
	public final static String COL_OCCASIONS = "col_occasions";
	public final static String COL_PIANO_DIFFICULTY = "col_piano_difficulty";
	public final static String COL_PIANO_FAMILIARITY = "col_piano_familiarity";
	public final static String COL_MELODY_COMPOSER = "col_melody_composer";
	public final static String COL_LYRIC_WRITTER = "col_lyric_writter";
	public final static String COL_LYRIC = "col_lyric";
	public final static String COL_ALBUMS = "col_albums";
	public final static String COL_TONALITY = "col_tonality";
	public final static String COL_TEMPO = "col_tempo";
	public final static String COL_VERSE = "col_verse";
	public final static String COL_STORY= "col_story";
	public final static String COL_MELODY = "col_melody";
	public final static String COL_HYMN_EVENTS = "col_hymn_events";
	public ArrayList<Map<String, Object>> hymns;
	
	public HashMap<String, Object> addDefaultHymn() {
		HashMap<String, Object> tempHashMap = new HashMap<String, Object>();
		
		tempHashMap.put(COL_SERIAL, 0 );   
        tempHashMap.put(COL_INDEX, 0);   
        tempHashMap.put(COL_TITLE, "歌名未知");   
        tempHashMap.put(COL_ALBUMS, "詩集未知");   
        tempHashMap.put(COL_RATING, 0);   
        tempHashMap.put(COL_FAMILIARITY, "普通熟");   
        tempHashMap.put(COL_TIMES, 0);
        	ArrayList<String> styles = new ArrayList<String>();
        	styles.add("尚無風格");
        tempHashMap.put(COL_STYLES, styles);
            ArrayList<String> occasions = new ArrayList<String>();
        	occasions.add("尚無場合");
        tempHashMap.put(COL_OCCASIONS, occasions);
		tempHashMap.put(COL_PIANO_DIFFICULTY, "難易度未知");
		tempHashMap.put(COL_PIANO_FAMILIARITY, "熟悉度未知");
		tempHashMap.put(COL_MELODY_COMPOSER, "作曲者未知");
		tempHashMap.put(COL_LYRIC_WRITTER, "作詞者未知");
		tempHashMap.put(COL_MELODY, "尚無歌譜");
		tempHashMap.put(COL_LYRIC, "尚無歌詞");
		tempHashMap.put(COL_TONALITY, "調性未知");
		tempHashMap.put(COL_TEMPO, "節奏未知");
		tempHashMap.put(COL_VERSE, "經節未知");
		tempHashMap.put(COL_STORY, "尚無故事");
			ArrayList<String> hymnEvents = new ArrayList<String>();
        	hymnEvents.add("尚無事件");
		tempHashMap.put(COL_HYMN_EVENTS, hymnEvents);
		
        return tempHashMap;  
	}	//END addDefaultHymn()
	
	public HashMap<String, Object> copyHymn(Map<String, Object> originMap){
    		HashMap<String, Object> tempMap = new HashMap<String, Object>();
    		
    		tempMap.put(COL_SERIAL, originMap.get(COL_SERIAL) );
    		tempMap.put(COL_INDEX, originMap.get(COL_INDEX) );
    		tempMap.put(COL_TITLE, originMap.get(COL_TITLE) );
   			tempMap.put(COL_RATING, originMap.get(COL_RATING).toString() );
   			tempMap.put(COL_FAMILIARITY, originMap.get(COL_FAMILIARITY).toString() );
   			tempMap.put(COL_TIMES, originMap.get(COL_TIMES).toString() );
   			
    	return tempMap;
	}	//END copyHymn()
	
	public ArrayList<Map<String, Object>> copyHymns(ArrayList<Map<String, Object>> rawHymns){
    	//這是一個deep clone(我不會用clone的方法...orz)
    	ArrayList<Map<String, Object>> tempHymns = new ArrayList<Map<String, Object>>();

    	for(Map<String, Object> map : rawHymns){
    		HashMap<String, Object> tempMap = copyHymn(map);
			tempHymns.add(tempMap);
    	}
    	return tempHymns;
    }//END copyHymns()
	
	//因為排序時要純資料，所以這些附加的資訊要在排序後加，
	//又因為如果把這些資料加進去後，之後的hymns會不能排序，所以用tempHymns暫存
	public ArrayList<Map<String, Object>> turnHymnsToListOfMap(ArrayList<Map<String, Object>> rawHymns){
    	//這是一個deep clone(我不會用clone的方法...orz)
    	ArrayList<Map<String, Object>> tempHymns = new ArrayList<Map<String, Object>>();

    	for(Map<String, Object> map : rawHymns){
    		HashMap<String, Object> tempMap = copyHymn(map);
    		
   			tempMap.put(COL_RATING, map.get(COL_RATING).toString() + "星等");
   			tempMap.put(COL_TIMES, map.get(COL_TIMES).toString() + "次");
			
			tempHymns.add(tempMap);
    	}
    	return tempHymns;
    }//END turnHymnsToListOfMap()
	
	public void debugShowOrder(ArrayList<Map<String, Object>> hymns){
		for(Map<String, Object> map : hymns){
			Log.d("列出在記憶體裡的順序", map.get(COL_SERIAL).toString() );
		}
	}
}	//END AppHymns
